```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>算法精解：数组中的第 K 个最大元素</title>
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            border-radius: 8px;
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        .info-card {
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(0,0,0,0.05);
        }
        .info-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 30px rgba(0,0,0,0.1);
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight::before {
            content: '';
            position: absolute;
            z-index: -1;
            top: 0;
            bottom: 0;
            left: -0.25em;
            right: -0.25em;
            background-color: rgba(255, 235, 59, 0.3);
            transform-origin: bottom center;
            transform: scaleY(0.1);
            transition: all 0.2s ease-in-out;
        }
        .highlight:hover::before {
            transform: scaleY(1);
            background-color: rgba(255, 235, 59, 0.5);
        }
        .mermaid {
            background-color: white;
            border-radius: 12px;
            padding: 24px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.05);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:py-32">
        <div class="container mx-auto max-w-6xl">
            <div class="flex flex-col md:flex-row items-center">
                <div class="md:w-1/2 mb-10 md:mb-0">
                    <h1 class="text-4xl md:text-5xl font-bold mb-4 leading-tight">数组中的第 K 个最大元素</h1>
                    <p class="text-xl md:text-2xl opacity-90 mb-8">高效算法解析与可视化实现</p>
                    <div class="flex space-x-3">
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">堆算法</span>
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">快速选择</span>
                        <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm font-medium">时间复杂度</span>
                    </div>
                </div>
                <div class="md:w-1/2 flex justify-center">
                    <div class="w-full max-w-md code-block p-6">
                        <div class="flex items-center text-gray-400 text-sm mb-4">
                            <div class="flex space-x-2 mr-4">
                                <span class="w-3 h-3 rounded-full bg-red-500"></span>
                                <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                                <span class="w-3 h-3 rounded-full bg-green-500"></span>
                            </div>
                            <span>findKthLargest.py</span>
                        </div>
                        <pre class="text-green-400 overflow-x-auto"><code>def findKthLargest(nums, k):
    from heapq import heappush, heappop
    heap = []
    for num in nums:
        heappush(heap, num)
        if len(heap) > k:
            heappop(heap)
    return heap[0]</code></pre>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-6xl">
            <!-- Problem Statement -->
            <div class="bg-white rounded-xl shadow-md p-8 mb-12">
                <div class="flex items-center mb-6">
                    <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                        <i class="fas fa-question text-purple-600"></i>
                    </div>
                    <h2 class="text-2xl font-bold">题目描述</h2>
                </div>
                <p class="text-gray-700 text-lg leading-relaxed">
                    给定一个未排序的整数数组，找到其中第 k 个最大的元素。请注意，你需要找的是数组排序后的第 k 个最大元素，而不是第 k 个不同的元素。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <!-- Heap Method -->
                <div class="info-card bg-white rounded-xl p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                            <i class="fas fa-layer-group text-blue-600"></i>
                        </div>
                        <h2 class="text-2xl font-bold">堆方法</h2>
                    </div>
                    <div class="space-y-4">
                        <p class="text-gray-700">
                            维护一个大小为 k 的最小堆，遍历数组后堆顶即为第 k 大元素。
                        </p>
                        <ul class="text-gray-700 space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>时间复杂度：O(n log k)</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>空间复杂度：O(k)</span>
                            </li>
                        </ul>
                    </div>
                </div>

                <!-- Quickselect Method -->
                <div class="info-card bg-white rounded-xl p-8">
                    <div class="flex items-center mb-6">
                        <div class="w-10 h-10 rounded-full bg-orange-100 flex items-center justify-center mr-4">
                            <i class="fas fa-bolt text-orange-600"></i>
                        </div>
                        <h2 class="text-2xl font-bold">快速选择法</h2>
                    </div>
                    <div class="space-y-4">
                        <p class="text-gray-700">
                            基于快速排序的分区思想，找到第 k 大的元素。
                        </p>
                        <ul class="text-gray-700 space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>平均时间复杂度：O(n)</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-exclamation-triangle text-yellow-500 mt-1 mr-2"></i>
                                <span>最坏情况：O(n²)</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                                <span>空间复杂度：O(1)</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <!-- Visual Explanation -->
            <div class="bg-white rounded-xl shadow-md p-8 mb-12">
                <div class="flex items-center mb-6">
                    <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center mr-4">
                        <i class="fas fa-project-diagram text-green-600"></i>
                    </div>
                    <h2 class="text-2xl font-bold">算法可视化</h2>
                </div>
                <div class="mermaid">
                    graph TD
                    A[数组] --> B{选择算法}
                    B -->|堆方法| C[构建最小堆]
                    C --> D[维护堆大小为k]
                    D --> E[堆顶即为结果]
                    B -->|快速选择| F[随机选取pivot]
                    F --> G[分区数组]
                    G --> H{判断位置}
                    H -->|等于k| I[返回结果]
                    H -->|小于k| J[处理右半部分]
                    H -->|大于k| K[处理左半部分]
                </div>
            </div>

            <!-- Code Implementation -->
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-12">
                <div class="flex border-b">
                    <button class="px-6 py-4 font-medium text-gray-700 border-b-2 border-purple-600 text-purple-600">Python 实现</button>
                </div>
                <div class="p-6">
                    <div class="code-block p-6 mb-8">
                        <div class="flex items-center text-gray-400 text-sm mb-4">
                            <div class="flex space-x-2 mr-4">
                                <span class="w-3 h-3 rounded-full bg-red-500"></span>
                                <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                                <span class="w-3 h-3 rounded-full bg-green-500"></span>
                            </div>
                            <span>heap_method.py</span>
                        </div>
                        <pre class="text-green-400 overflow-x-auto"><code>def findKthLargest(nums, k):
    from heapq import heappush, heappop
    heap = []
    for num in nums:
        heappush(heap, num)
        if len(heap) > k:
            heappop(heap)
    return heap[0]</code></pre>
                    </div>

                    <div class="code-block p-6">
                        <div class="flex items-center text-gray-400 text-sm mb-4">
                            <div class="flex space-x-2 mr-4">
                                <span class="w-3 h-3 rounded-full bg-red-500"></span>
                                <span class="w-3 h-3 rounded-full bg-yellow-500"></span>
                                <span class="w-3 h-3 rounded-full bg-green-500"></span>
                            </div>
                            <span>quickselect.py</span>
                        </div>
                        <pre class="text-green-400 overflow-x-auto"><code>def findKthLargest(nums, k):
    def partition(left, right, pivot_index):
        pivot = nums[pivot_index]
        nums[pivot_index], nums[right] = nums[right], nums[pivot_index]
        store_index = left
        for i in range(left, right):
            if nums[i] < pivot:
                nums[store_index], nums[i] = nums[i], nums[store_index]
                store_index += 1
        nums[right], nums[store_index] = nums[store_index], nums[right]
        return store_index

    def select(left, right, k_smallest):
        if left == right:
            return nums[left]
        pivot_index = random.randint(left, right)
        pivot_index = partition(left, right, pivot_index)
        if k_smallest == pivot_index:
            return nums[k_smallest]
        elif k_smallest < pivot_index:
            return select(left, pivot_index - 1, k_smallest)
        else:
            return select(pivot_index + 1, right, k_smallest)

    return select(0, len(nums) - 1, len(nums) - k)</code></pre>
                    </div>
                </div>
            </div>

            <!-- Key Takeaways -->
            <div class="bg-white rounded-xl shadow-md p-8">
                <div class="flex items-center mb-6">
                    <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center mr-4">
                        <i class="fas fa-lightbulb text-indigo-600"></i>
                    </div>
                    <h2 class="text-2xl font-bold">核心要点</h2>
                </div>
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="font-bold text-lg mb-3 flex items-center">
                            <i class="fas fa-layer-group text-blue-500 mr-2"></i>
                            堆方法适用场景
                        </h3>
                        <ul class="text-gray-700 space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check text-blue-500 mt-1 mr-2"></i>
                                <span>当 k 远小于 n 时效率高</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-blue-500 mt-1 mr-2"></i>
                                <span>实现简单，适合面试快速编写</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-blue-500 mt-1 mr-2"></i>
                                <span>适用于流式数据或不能一次性加载全部数据的情况</span>
                            </li>
                        </ul>
                    </div>
                    <div class="bg-gray-50 p-6 rounded-lg">
                        <h3 class="font-bold text-lg mb-3 flex items-center">
                            <i class="fas fa-bolt text-orange-500 mr-2"></i>
                            快速选择法优势
                        </h3>
                        <ul class="text-gray-700 space-y-2">
                            <li class="flex items-start">
                                <i class="fas fa-check text-orange-500 mt-1 mr-2"></i>
                                <span>平均情况下时间复杂度最优</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-orange-500 mt-1 mr-2"></i>
                                <span>原地操作，空间效率高</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-orange-500 mt-1 mr-2"></i>
                                <span>可以通过随机化pivot避免最坏情况</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis',
            }
        });
        
        // 微交互效果
        document.querySelectorAll('.highlight').forEach(el => {
            el.addEventListener('mouseenter', () => {
                el.classList.add('animate-pulse');
            });
            el.addEventListener('mouseleave', () => {
                el.classList.remove('animate-pulse');
            });
        });
    </script>
</body>
</html>
```